package com.adams.audit.operate;

import java.util.List;

import junit.framework.Assert;
import junit.framework.TestCase;

import com.adams.access.db.bean.AuditRecord;
import com.adams.audit.operate.service.IAuditRecordService;
import com.adams.audit.web.bean.AuditType;
import com.adams.utils.AppContext;

public class AuditRecordServiceTestBean extends TestCase
{

	private static IAuditRecordService auditRecordService;
	private static AuditRecord auditRecord;

	static
	{
		AppContext.load("applicationContext-test.xml");
		auditRecordService = (IAuditRecordService) AppContext
				.getBean("auditRecordService");
		sendAuditNotice();
		auditRecord = viewAuditFlow();
	}

	public void testGetAllType()
	{
		List<AuditType> list = auditRecordService.getAllType();
		Assert.assertNotNull(list);
	}

	public void testListAuditRecord()
	{
		int pageSize = auditRecordService.listAuditRecord("", "", 1, 10)
				.getPageSize();
		Assert.assertEquals(10, pageSize);
	}

	public void testListHasAuditRecord()
	{
		int pageSize = auditRecordService.listHasAuditRecord("", 1, 10)
				.getPageSize();
		Assert.assertEquals(10, pageSize);
	}

	// public void testAgree()
	// {
	// auditRecordService.agree(auditRecord);
	// Assert.assertEquals(AuditConstants.AUDIT_PASS, auditRecord
	// .getAuditStatus());
	// }
	//
	// public void testRefuse()
	// {
	// auditRecordService.refuse(auditRecord);
	// Assert.assertEquals(AuditConstants.AUDIT_OVERRULE, auditRecord
	// .getAuditStatus());
	// }

	private static AuditRecord viewAuditFlow()
	{
		List<AuditRecord> list = auditRecordService.viewAuditFlow("contentId",
				"article", 1, 10).getResultList();
		if (list != null && list.size() > 0)
			return list.get(0);
		else
			return null;
	}

	private static void sendAuditNotice()
	{
		boolean flag1 = auditRecordService.sendAuditNotice("contentId",
				"businessaaa", "测试用例", 1, "viewUrl", 1);
		Assert.assertFalse(flag1);
		boolean flag2 = auditRecordService.sendAuditNotice("contentId",
				"article", "测试用例", 1, "viewUrl", 1);
		Assert.assertTrue(flag2);
	}

	@Override
	protected void tearDown() throws Exception
	{
		auditRecordService.deleteRecord("contentId", "businessaaa");
		auditRecordService.deleteRecord("contentId", "article");
	}
}
